﻿using hyjx;
using hyjx.bind;
using FeedingReport.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FeedingReport.Models
{
    /// <summary>
    /// 筛选模型
    /// </summary>
    public class FilterModel : BindableBase
    {
        /// <summary>
        /// 创建一个新的筛选模型
        /// </summary>
        public FilterModel() 
        {
            if(App.Mixers != null)
            {
                foreach (var item in App.Mixers)
                {
                    MixerNames.Add(item, item);
                }
                SelectedMixerName = MixerNames.First();
            }

            if(App.Materials != null)
            {
                foreach (var item in App.Materials)
                {
                    PowderTypes.Add(item.Code, item.Value);
                }
                SelectedPowderType = PowderTypes.First();
            }
            
            

            SortFields.Add("CreatedTime", "开始时间");
            SortFields.Add("MaterialCode", "物料类别");
            SelectedSortField = SortFields.First();

            OrderByFields.Add(OrderbyDirectionTypes.Ascending, "顺序");
            OrderByFields.Add(OrderbyDirectionTypes.Descending, "倒序");
            SelectedOrderByField = OrderByFields.First();
        }

        private KeyValuePair<string,string> _selectedMixerName;
        /// <summary>
        /// 搅拌机名称
        /// </summary>
        public KeyValuePair<string, string> SelectedMixerName { get { return _selectedMixerName; } set { SetProperty(ref _selectedMixerName, value); } }
        /// <summary>
        /// 搅拌机名称集
        /// </summary>
        public Dictionary<string, string> MixerNames { get; } = new Dictionary<string, string>();
        /// <summary>
        /// 粉体类别集
        /// </summary>
        public Dictionary<int, string> PowderTypes { get; } = new Dictionary<int, string>();

        private KeyValuePair<int, string> _selectedPowderType;
        /// <summary>
        /// 选中的粉体类别
        /// </summary>
        public KeyValuePair<int, string> SelectedPowderType { get {  return _selectedPowderType; } set { SetProperty(ref _selectedPowderType, value); } }

        private DateTime? _startDate;
        /// <summary>
        /// 开始日期
        /// </summary>
        public DateTime? StartDate { get { return _startDate; } set { SetProperty(ref _startDate, value);} }

        private DateTime? _endDate;
        /// <summary>
        /// 截止日期
        /// </summary>
        public DateTime? EndDate { get { return _endDate;} set { SetProperty(ref _endDate, value); } }
        /// <summary>
        /// 排序字段集
        /// </summary>
        public Dictionary<string, string> SortFields { get; } = new Dictionary<string,string>();

        private KeyValuePair<string, string> _selectedSortField;
        /// <summary>
        /// 选中的排序字段
        /// </summary>
        public KeyValuePair<string,string> SelectedSortField { get { return _selectedSortField; } set { SetProperty(ref _selectedSortField, value); } }
        /// <summary>
        /// 排序顺序集
        /// </summary>
        public Dictionary<OrderbyDirectionTypes, string> OrderByFields { get; } = new Dictionary<OrderbyDirectionTypes, string>();

        private KeyValuePair<OrderbyDirectionTypes, string> _selectedOrderByField;
        /// <summary>
        /// 选中的排序顺序
        /// </summary>
        public KeyValuePair<OrderbyDirectionTypes, string> SelectedOrderByField { get { return _selectedOrderByField; } set { SetProperty(ref _selectedOrderByField, value); } }
        /// <summary>
        /// 筛选命令
        /// </summary>
        public FilterCommand FilterCommand { get; } = new();
    }
}
